<?php

class Home_MemberController extends BaseController
{

	public function __construct()
	{
		parent::__construct();
	}

	public function indexAction() 
	{
		$this->listAction();
	}	
	
	public function listAction() 
	{
		$this->oView->title = 'Member';
		$this->oView->box_title = 'List Member';
		
		$objMember = new Member();
		
		$rsMembers = $objMember->getRowset();
		$this->oView->rsMembers = $rsMembers;		
		
		$this->renderView('home/member/list');
	}
	
	public function addAction()
	{
		$this->oView->title = 'Member';
		$this->oView->box_title = "Add New Member";
		$this->oView->box_action = "Add New Member";
		
		$this->oView->link_url = site_url('home/member/add');		
		$this->oView->cancel_url = site_url('home/member/list');

		if ($this->oParams->isPost()) 
		{
			// TODO : Check validate
			
			$data = array(
				"fbid" => $this->oParams->varPost("fbid",""),					
				"fullname" => $this->oParams->varPost("fullname",""),					
				"username" => $this->oParams->varPost("username",""),					
				"email" => $this->oParams->varPost("email","")
			);
			
			// TODO : Notify save successfully
			$oMember = new Member();
			$oMember->insert($data);			
		}
		
		$this->renderView('home/member/_form');
	}
	
	public function editAction($member_id)
	{
		$this->oView->title = 'Member';		
		$this->oView->box_title = "Update Member";
		$this->oView->link_url = site_url('home/member/edit/'.$member_id);
		$this->oView->cancel_url = site_url('home/member/list');
	
		$oMember = new Member();
		
		if ($this->oParams->isPost())
		{
			// TODO : Check validate
			$data = array(
				"fbid" => $this->oParams->varPost("fbid",""),					
				"fullname" => $this->oParams->varPost("fullname",""),					
				"username" => $this->oParams->varPost("username",""),					
				"email" => $this->oParams->varPost("email","")
			);
			
			// TODO : Notify save successfully
			$oMember->update($member_id,$data);
		}		
		
		$rowMember = $oMember->get($member_id);
		$this->oView->rowMember = $rowMember;
		
		$this->renderView('home/member/_form');
	}
	
	public function deleteAction($member_id)
	{
		// TODO : Check validate $member_id
		$oMember = new Member();
		$oMember->delete($member_id);
		redirect("home/member/list");
	}
	

}
